package com.easywan.web.controller.clothes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easywan.core.BaseController;
import com.easywan.pojo.IResult;
import com.easywan.pojo.IResultSupport;
import com.easywan.service.IToolsClothesSizeService;

import junit.framework.Assert;
import net.sf.json.JSONObject;


@Controller
@RequestMapping("clothes")
public class ClothesSizeController extends BaseController{
	@Autowired
	IToolsClothesSizeService clothesSizeService;
	/**
	 * 根据
	 * 		衣服的类别
	 * 		人的体重
	 * 		身高
	 * 获取 适合自己穿的衣服
	 * @return
	 */
	@RequestMapping("clothesSize")
	public String clothesSize(){
		return "clothes/clothesSize.jsp";
	}
	@ResponseBody
	@RequestMapping(value = "getSize",produces="text/html;charset=UTF-8")
	public String getSize(HttpServletRequest request,HttpServletResponse response){
		try{
			int height = getInt(request,"height");
			int weight = getInt(request,"weight");
			int people = getInt(request,"people");
			//paramsNotNull(height,weight,people);
			Assert.assertEquals(height, -1);
			Assert.assertEquals(weight, -1);
			Assert.assertEquals(people, -1);
			Integer type = getInt(request,"type");
			IResult result = clothesSizeService.getSize(height, weight, people, type);
			return JSONObject.fromObject(result).toString();
		}catch(Exception e){
			return JSONObject.fromObject(
						IResultSupport.buildResult(IResult.FAILT_CODE, e.getMessage())
					).toString();
		}
	}
	
}
